package xyz.yuanjilu.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSONObject;
import com.cybermkd.mongo.kit.MongoQuery;

import xyz.yuanjilu.service.BaseMongoDao;
import xyz.yuanjilu.service.BaseMongoService;

public abstract class BaseMongoServiceImpl implements BaseMongoService{
	@Autowired
	private BaseMongoDao mongoDao;
	
//	protected abstract String getDataBase();
	
	protected abstract String getUse();

	@Override
	public String save(Object obj) {
		return mongoDao.save( getUse(), obj);
	}

	@Override
	public MongoQuery query() {
		return mongoDao.query(getUse());
	}
	@Override
	public void close() {
		mongoDao.close();
	}
	
	@Override
    public Long update(JSONObject entity) {
        String id = entity.getString("_id");
        return query().byId(id).replace(entity);
    }

}
